Skip to content

fix(id): keep space-form --new from swallowing the subcommand (#3144) - #4326

Merged
dezren39 merged 1 commit into
mainfrom
queue/5655-3144-new-subcommand
Nov 2, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/5655-3144-new-subcommand

Conversation

@dezren39

@dezren39 dezren39 commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Fixes #3144. Queue task 5655.

Problem

--new is a global Option<String> with num_args = 0..=1, so clap greedily consumes the next token as the instance name. The documented id --new serve created .iroh/serve/ and started the REPL instead of serving under a random name.

Change

  • pkgs/id/src/cli.rs: new Cli::normalize_args argv pre-pass. When a bare --new is followed by a top-level subcommand name (and no subcommand has been seen yet), it rewrites that --new to --new= — the empty value still means "random name" and the token then parses as the subcommand. The name set is read from the clap definition itself (names + aliases), so it cannot drift from the real parser. Global flag values that spell a subcommand (e.g. --log-level list) are not mistaken for one, and everything after -- is left alone.
  • pkgs/id/src/main.rs: parse through normalize_args(std::env::args_os()).
  • Preserved forms: bare --new, --new=<name>, --new <name> <command>, trailing serve --new. No --data-dir behavior change.

Tests (laptop, head 7fc37e8)

  • New lib tests: test_cli_parse_new_space_form_subcommand_not_swallowed, test_cli_parse_new_forms_preserved, test_normalize_args_rewrites_only_the_ambiguous_form — all pass. (They parse on a big-stack thread, the module's existing convention for deep clap parses.)
  • New integration tests: test_new_flag_space_form_subcommand_not_swallowed (id --new id succeeds, creates exactly one 8-hex instance dir, no .iroh/id/), test_new_flag_space_form_named — pass. Full test_new_flag* set: 6/6 pass.
  • Known pre-existing local failure, unrelated: lib test test_cli_parse_world_new_and_stats stack-overflows in this laptop's libtest setup on unmodified branch state too (verified on the fleet/5215 worktree); it does not use the big-stack workaround the neighboring parse tests use.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Cli::normalize_args rewrites a bare --new followed by a top-level subcommand name to --new= before clap parses, so the documented id --new serve runs serve under a random instance name instead of creating .iroh/serve/ and starting the REPL. Subcommand names come from the clap definition itself (names + aliases), so the list cannot drift. Named, equals, bare, and trailing forms are preserved; global flag values that spell a subcommand are not mistaken for one. main.rs parses through normalize_args.

Tests: 3 new lib parse/normalize tests and 2 new CLI integration tests (space-form subcommand runs under an 8-hex random instance; space-form named instance). Existing --new integration tests still pass (6/6 test_new_flag*).
@dezren39
dezren39 requested a review from a team as a code owner November 2, 2026 10:43
@coderabbitai

coderabbitai Bot commented Nov 2, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 23 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b95aeed1-418a-41c2-b207-e0d00dbb9a7b
Commits

Reviewing files that changed from the base of the PR and between c08b27f and 7fc37e8.

Files selected for processing: 3
  • pkgs/id/src/cli.rs
  • pkgs/id/src/main.rs
  • pkgs/id/tests/cli_integration.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T10:45:17.800772Z 7fc37e8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39
dezren39 merged commit aa4fbe8 into main Nov 2, 2026
2 of 4 checks passed
@dezren39
dezren39 deleted the queue/5655-3144-new-subcommand branch November 2, 2026 10:46
@dezren39
dezren39 restored the queue/5655-3144-new-subcommand branch November 8, 2026 04:18
@dezren39
dezren39 deleted the queue/5655-3144-new-subcommand branch November 8, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant